package com.xyht.sca_s.student_manage_system.modules.scheduleManagement.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.scheduleManagement.entity.req.SmsScheduleSubscribeReq;
import com.xyht.sca_s.student_manage_system.modules.scheduleManagement.service.SmsScheduleSubscribeService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 日程订阅表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-08-14
 */
@RestController
@RequestMapping("/schedule/subscribe")
@SecretBody
public class SmsScheduleSubscribeController {
    @Autowired
    private SmsScheduleSubscribeService smsScheduleSubscribeService;
    @Autowired
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "添加订阅")
    @PostMapping("/add")
    @RepeatRequestCheck
    public ResponseResult addSubscribe(@RequestBody SmsScheduleSubscribeReq subscribeReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsScheduleSubscribeService.addSubscribe(subscribeReq,user_id);
    }

    @ApiModelProperty(value = "查询订阅列表")
    @GetMapping("/list")
    public ResponseResult getSubscribeList(HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsScheduleSubscribeService.getSubscribeList(user_id);
    }

    @ApiModelProperty(value = "修改订阅")
    @PostMapping("/update")
    public ResponseResult updateSubscribeList(@RequestBody SmsScheduleSubscribeReq subscribeReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsScheduleSubscribeService.updateSubscribeList(subscribeReq,user_id);
    }

    @ApiModelProperty(value = "取消订阅")
    @PostMapping("/cancel")
    @RepeatRequestCheck
    public ResponseResult cancelSubscribeList(@RequestBody SmsScheduleSubscribeReq subscribeReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsScheduleSubscribeService.cancelSubscribeList(subscribeReq,user_id);
    }


}

